package com.liu.case3;


import java.util.ArrayList;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

/**
 * @Author 老刘Matthew
 * @Timestamp 2022/8/6 20:33
 * @Description
 */
public class ParseCase {

    public static void main(String[] args) throws Exception {

        List<Bean> list = new ArrayList<>();

        SAXReader reader = new SAXReader();

        Document document = reader.read("src/resources/student.xml");

        List<Element> list_ = document.getRootElement().elements();

        for (Element e : list_) {

            int id = Integer.valueOf(e.attributeValue("id"));
            String name = e.element("name").getText();
            int age = Integer.valueOf(e.element("age").getText());
            String address = e.element("address").getText();
            Bean book = new Bean(id, name, age, address);

            list.add(book);
        }

        for (Bean b : list) {
            System.out.println(b);
        }
    }

}